<template>
  <el-dialog
    :model-value="dialog"
    :width="width"
    draggable
    overflow
    :append-to-body="false"
    :show-close="false"
    :align-center="true"
    :destroy-on-close="true"
    :close-on-press-escape="false"
    :close-on-click-modal="false"
  >
    <template #header>
      <div class="header">
        <div class="title">{{ title }}</div>
        <div class="close" @click="close">
          <el-icon>
            <Close />
          </el-icon>
        </div>
      </div>
    </template>
    <!-- 接收外部传入的 default 插槽 -->
    <template #default>
        <div class="dialog">
            <slot></slot>
        </div>
    </template>
    <!-- 接收外部传入的 footer 插槽 -->
    <template #footer v-if="is_display_footer">
      <div class="footer">
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="sure">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>

<script setup>
import { Close } from "@element-plus/icons-vue";

const props = defineProps({
  dialog: {
    type: Boolean,
    default: false,
  },
  title: {
    type: String,
    default: "",
  },
  width: {
    type: String,
    default: "500px",
  },
  is_display_footer:{
    type: Boolean,
    default: true,
  }
});
const emit = defineEmits(["close", "sure"]);

// const dialog_active = computed(()=>{
//   return props.dialog;
// })

const close = () => {
  emit("close");
};

const sure = () => {
  emit("sure");
};
</script>

<style scoped lang="less">
.header {
  width: 100%;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  //   background-image: linear-gradient(
  //     to right,
  //     #dae2f8 0%,
  //     #d6a4a4 51%,
  //     #dae2f8 100%
  //   );
  background-image: var(--title-bg);
  transition: 0.4s;
  background-size: 200% auto;
  color: #fff;
  border-top-left-radius: 5px;
  border-top-right-radius: 5px;

  &:hover {
    background-position: right center;
    /* change the direction of the change here */
  }

  .title {
    margin-left: 30px;
  }

  .close {
    width: 40px;
    font-size: 30px;
    height: 100%;
    text-align: center;
    background-color: rgba(255, 255, 255, 0.3);
    cursor: pointer;
  }
}
.dialog{
    width: 100%;
    padding: 10px;
    box-sizing: border-box;
}
.footer {
  box-sizing: border-box;
  padding: 5px 10px !important;
  width: 100%;
  display: flex;
  justify-content: flex-end;
}
</style>
